package com.example.springlist.controller;

import com.example.springlist.business.entity.Todos;
import com.example.springlist.business.service.TodosServer;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/item")
public class TodosController {

    TodosServer todosServer;
    @GetMapping("/test")
    public String test(){
        return "hello world";
    }
    @Autowired
    public TodosController(TodosServer todosServer) {
        this.todosServer = todosServer;
    }

    @GetMapping("/showAll")
    public List<Todos> showAll(){
        return todosServer.list();
    }


    @GetMapping("/selectAll")
    public List<Todos> selectAll(@Param("done") int done) {
        int t = todosServer.selectAll(done);
        return todosServer.list();
    }

    @GetMapping("/selectById")
    public List<Todos> selectById(@Param("done") int done, @Param("id") int id) {
        int t = todosServer.selectById(done, id);
        return todosServer.list();
    }

    @DeleteMapping("/del/{id}")
    public List<Todos> deleteById(@PathVariable("id") int id) {
        int t = todosServer.deleteById(id);
        return todosServer.list();
    }
    @DeleteMapping("/delAll")
    public List<Todos> deleteAll() {
        int t = todosServer.deleteAll();
        return todosServer.list();
    }

    @PostMapping("/add")
    public List<Todos> add(@RequestBody Todos todos){
        int t = todosServer.add(todos);
        return todosServer.list();
    }



}
